

from typing import Generic, List, TypeVar
from typing import Literal, Optional
from pydantic import BaseModel
from sqlmodel import Field

class PageRequestParams(BaseModel):
    "分页查询参数"
    page: int = Field(default=1,ge=1,title="页码")
    limit: int = Field(default=10,gt=0,le=100, title="每页数量")
    order_by: Optional[Literal["update_at","create_at"]] = Field(default="update_at", title="排序字段")
    order_type: Optional[Literal["asc","desc"]] = Field(default="desc", title="排序类型")
    keyword: Optional[str] = Field(default=None, title="搜索关键字", description="用于模糊搜索的关键字")

T = TypeVar("T")
class PageResponse(BaseModel,Generic[T]):
    total: int = Field(default=0, title="数据总数")
    current_page: int = Field(default=1, title="当前页码")
    total_pages: int = Field(default=1, title="总页数")
    page_size: int = Field(default=10, title="每页条数")
    has_next_page: bool = Field(default=False, title="是否有下一页")
    has_previous_page: bool = Field(default=False, title="是否有上一页")
    data: Optional[list[T]] = Field(default=None, title="数据列表")